const BitShares = require('btsdex')

assetDict = {}
accountDict = {}

async function getAssetSymbol(assetId) {
    var asset = assetDict[assetId]
    if (asset == undefined) {
        assetObj = await BitShares.assets.id(assetId)
        assetDict[assetId] = assetObj
    }
    return assetDict[assetId]
}

async function getLastPrice(assetName) {
    var baseSymbol = "BRIDGE.BTC"

    var ticker = await BitShares.ticker(baseSymbol, assetName)
    lastPrice = ticker.latest * 100000000
    return lastPrice
}

async function getAccountName(accountId) {
    account = accountDict[accountId]
    if (account == undefined) {
        accountObj = await BitShares.accounts.id(accountId)
        accountDict[accountId] = accountObj.name
    }

    return accountDict[accountId]
}

module.exports = {
    getAssetSymbol: getAssetSymbol,
    getAccountName: getAccountName,
    getLastPrice: getLastPrice
}